package com.xmindguoguo.boot.config;

import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.xmindguoguo.boot.common.annotation.DBRepository1;
import com.xmindguoguo.boot.common.annotation.DBRepository2;

/**
 * 配置MyBatis Mapper Scanner
 * 
 * @author XuJijun
 *
 */
@Configuration
@AutoConfigureAfter(MybatisConfig.class)
public class MyBatisMapperScannerConfig {

    /**
     * - 设置SqlSessionFactory； - 设置dao所在的package路径； - 关联注解在dao类上的Annotation名字；
     */
    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer1() {

        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory1");
        mapperScannerConfigurer.setBasePackage("com.xmindguoguo.boot");
        mapperScannerConfigurer.setAnnotationClass(DBRepository1.class);
        return mapperScannerConfigurer;
    }

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer2() {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory2");
        mapperScannerConfigurer.setBasePackage("com.xmindguoguo.boot");
        mapperScannerConfigurer.setAnnotationClass(DBRepository2.class);
        return mapperScannerConfigurer;
    }

}
